﻿@{
    ViewData["Title"] = "PersonUser";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!--个人信息页面-->
<div style="margin:60px 60px">
    <body>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" id="account" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>



            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="text" id="employeeSex" lay-verify="required" readonly autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" id="employeeName" lay-verify="required" readonly autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">证件类型</label>
                <div class="layui-input-block">
                    <input type="text" id="certificateId" lay-verify="required" readonly autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">证件号码</label>
                <div class="layui-input-block">
                    <input type="text" id="idNumber" lay-verify="required" readonly autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">手机号码</label>
                <div class="layui-input-block">
                    <input type="text" id="employeePhone" lay-verify="required" readonly autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="password" id="password"> <!--密码-->
                    <input type="hidden" name="createBy" id="createBy"> <!--创建人-->
                    <input type="hidden" name="createDate" id="createDate"> <!--创建时间-->
                    <input type="hidden" name="departId" id="departId"> <!--部门编号 外键-->

                    <input type="hidden" name="employeeState" id="employeeState"> <!--员工状态-->
                    <input type="hidden" name="entryDate" id="entryDate"> <!--入职日期-->
                    <input type="hidden" name="isDel" id="isDel"> <!--逻辑删除状态列-->
                    <input type="hidden" name="location" id="location"> <!--所在地-->
                    <input type="hidden" name="office" id="office"> <!--岗位-->
                    <input type="hidden" name="personnelLevel" id="personnelLevel"> <!--人事级别-->
                    <input type="hidden" name="position" id="position"> <!--职务-->
                    <input type="hidden" name="roleId" id="roleId"> <!--角色编号  外键-->
                    <input type="hidden" name="unitId" id="unitId"> <!--单位编号  外键-->
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" onclick="LineAdd()">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>

        </form>

        <!--反填用户信息-->
        <script>
            var $ = layui.$;



            function getUserInfo() {
                //var account = $("#account").val();
                $.get("http://10.31.60.18:8000/AuthorizationPeopleGetRout/api/RoleShow/BackEmployeeInfo?EmployeeId=" + 4, function (data) {
                    console.log(data);
                    $("#account").val(data.account);
                    $("#employeeSex").val(data.employeeSex=="0"?"女":"男");
                    $("#employeeName").val(data.employeeName);
                    $("#certificateId").val(data.certificateId);
                    $("#idNumber").val(data.idNumber);
                    $("#employeePhone").val(data.employeePhone);
                    $("#password").val(data.password);


                    $("#createBy").val(data.createBy);
                    $("#createDate").val(data.createDate);
                    $("#departId").val(data.departId);
                    $("#employeeState").val(data.employeeState);
                    $("#entryDate").val(data.entryDate);
                    $("#isDel").val(data.isDel);
                    $("#location").val(data.location);
                    $("#office").val(data.office);
                    $("#personnelLevel").val(data.personnelLevel);
                    $("#position").val(data.position);
                    $("#roleId").val(data.roleId);
                    $("#unitId").val(data.unitId);
                });
            }
            //首次加载调用
            getUserInfo();

            //修改
            function LineAdd() {
                var obj = {
                    employeeId: 4,
                    account: $("#account").val(),
                    employeeSex: $("#employeeSex").val(),
                    employeeName: $("#employeeName").val(),
                    certificateId: $("#certificateId").val(),
                    idNumber: $("#idNumber").val(),
                    employeePhone: $("#employeePhone").val(),

                    password: $("#password").val(),
                    createBy: $("#createBy").val(),
                    createDate: $("#createDate").val(),
                    departId: $("#departId").val(),
                    employeeState: $("#employeeState").val(),
                    entryDate: $("#entryDate").val(),
                    location: $("#location").val(),
                    office: $("#office").val(),
                    personnelLevel: $("#personnelLevel").val(),
                    position: $("#position").val(),
                    roleId: $("#roleId").val(),
                    unitId: $("#unitId").val(),
                }
                console.log(obj)
                $.ajax({
                    url: "http://10.31.60.18:8000/AuthorizationPeopleSetRout/api/Employee/UpdateEmployee",
                    //url: "http://localhost:5207/api/Employee/UpdateEmployee",
                    type: "put",
                    data: JSON.stringify(obj),
                    contentType: "application/json",
                    success: res => {
                        if (res > 0) {
                            alert("修改成功！");
                            getUserInfo();
                        }
                        else {
                            alert("修改失败！");
                        }
                    }
                });
            }

        </script>
    </body>
</div>